package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PmsFile;
import com.ruoyi.system.service.IPmsFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件储存Controller
 * 
 * @author ruoyi
 * @date 2024-12-02
 */
@RestController
@RequestMapping("/system/file")
public class PmsFileController extends BaseController
{
    @Autowired
    private IPmsFileService pmsFileService;

    /**
     * 查询文件储存列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsFile pmsFile)
    {
        startPage();
        List<PmsFile> list = pmsFileService.selectPmsFileList(pmsFile);
        return getDataTable(list);
    }

    /**
     * 导出文件储存列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:export')")
    @Log(title = "文件储存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsFile pmsFile)
    {
        List<PmsFile> list = pmsFileService.selectPmsFileList(pmsFile);
        ExcelUtil<PmsFile> util = new ExcelUtil<PmsFile>(PmsFile.class);
        util.exportExcel(response, list, "文件储存数据");
    }

    /**
     * 获取文件储存详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{pmsFileId}")
    public AjaxResult getInfo(@PathVariable("pmsFileId") Long pmsFileId)
    {
        return success(pmsFileService.selectPmsFileByPmsFileId(pmsFileId));
    }

    /**
     * 新增文件储存
     */
    @PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "文件储存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsFile pmsFile)
    {
        return toAjax(pmsFileService.insertPmsFile(pmsFile));
    }

    /**
     * 修改文件储存
     */
    @PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "文件储存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsFile pmsFile)
    {
        return toAjax(pmsFileService.updatePmsFile(pmsFile));
    }

    /**
     * 删除文件储存
     */
    @PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "文件储存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pmsFileIds}")
    public AjaxResult remove(@PathVariable Long[] pmsFileIds)
    {
        return toAjax(pmsFileService.deletePmsFileByPmsFileIds(pmsFileIds));
    }
}
